package trafficgeneratorcr.writer;

import java.io.*;


public class CSVWriter {

    private static final String separator = ", ";

    private int[][][] outputTables;
    private String baseFileName;

    public CSVWriter(int[][][] outputTables, String baseFileName) {
        this.outputTables = outputTables;
        this.baseFileName = baseFileName;
    }

    public void writeOutput() throws FileNotFoundException {
        for (int type = 0; type < outputTables.length; type++) {
            String fileName = baseFileName.substring(0, baseFileName.lastIndexOf(".")) +
                    type +
                    baseFileName.substring(baseFileName.lastIndexOf("."));

            PrintStream ps = new PrintStream(fileName);

            for (int timeSliceIndex = 0; timeSliceIndex < outputTables[type][0].length; timeSliceIndex++) {
                for (int weekIndex = 0; weekIndex < outputTables[type].length; weekIndex++) {
                    int value = outputTables[type][weekIndex][timeSliceIndex];

                    ps.print(value + separator);
                }

                ps.println();
            }

            ps.close();
        }
    }
    
}
